"use strict";

(function (e) {
  var r = function () {},
    l = function () {
      this.option = {
        name: "body", //父级元素 标签name值
        fontsize: 12, //文字大小
        fontclose: "#ccc", //文字大小
        color: ["#94f712","#fac61b","#fa1b1b"], //loading 字体颜色
        backgroundColor: "#ffffff", //loading状态条背景色
        top: 10, //margin-top
        width: 3, //width
        height: 6, //height
      };
      this._op = {
        index: 0,
      };
    };
  //初始化
  r.prototype.init = l;
  //打开
  l.prototype.open = function (option) {
    this._opt = Object.assign({}, this.option, option);
 
    l.prototype.index = this._op.index;
    $(this.option.name).append("<div name='loading'><span style='background-color:"+this._opt.color[0]+";height:"+this._opt.height+"px;width:"+this._opt.width+"px'></span>"+
    "<span style='background-color:"+this._opt.color[1]+";height:"+this._opt.height+"px;width:"+this._opt.width+"px'></span>"+
    "<span style='background-color:"+this._opt.color[2]+";height:"+this._opt.height+"px;width:"+this._opt.width+"px'></span></div>");
  };
  //关闭
  l.prototype.close = function (option) {
    $("div[name=loading]").remove(); //删除加载状态
  };
  //文字
  l.prototype.text = function (str) {
    var _loadingstr = str ? str : "我也是有底线的哦！";
    $(this.option.name).append("<div name='loading' style='background-color:"+this._opt.backgroundColor+";font-size:"+this._opt.fontsize+"px;color:"+this._opt.fontclose+"'>" + _loadingstr + "</div>");
  };
  //状态
  l.prototype.state = function () {
    if ($("div[name=loading]").length == 1) {
        return true
    } else {
        return false
    }
  };
  e.loading = new r();
})(window);
